package controllers

import (
	"gdshop-admin-go-api/app/request/BaseReq"
	"gdshop-admin-go-api/app/service/AdminService"
	"gdshop-admin-go-api/app/service/BaseService"
	"gdshop-admin-go-api/library/response"
	"gdshop-admin-go-api/library/tools/token"
	"github.com/gogf/gf/net/ghttp"
)

type AdminController struct {
	*BaseController
}

func NewAdminController(inputReq *BaseReq.I) *AdminController {
	return &AdminController{
		&BaseController{Req: inputReq},
	}
}
func (c *AdminController) Info(r *ghttp.Request) *response.JsonResponse {
	if err := c.checkId(r); err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}
	return AdminService.Info(r.GetCtx(), c.Req)
}

func (c *AdminController) Update(r *ghttp.Request) *response.JsonResponse {
	if c.Req.UpdateReq != nil {
		if err := r.Parse(c.Req.UpdateReq); err != nil {
			return response.FailByRequestMessage(r, err.Error())
		}
	}
	if err := c.checkId(r); err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}
	return AdminService.Update(r, c.Req)
}
func (c *AdminController) Add(r *ghttp.Request) *response.JsonResponse {
	if c.Req.AddReq != nil {
		if err := r.Parse(c.Req.AddReq); err != nil {
			return response.FailByRequestMessage(r, err.Error())
		}
	}
	return AdminService.Add(r, c.Req)
}

func (c *AdminController) Page(r *ghttp.Request) *response.JsonResponse {
	if err := r.Parse(&c.Req.PageInfo); err != nil {
		return response.FailByRequestMessage(r, err.Error())
	}
	return AdminService.Page(r, c.Req)
}

func (c *AdminController) Move(r *ghttp.Request) *response.JsonResponse {
	return BaseService.CategoryMove(r, c.Req.TableName, r.GetInt("departmentId"), r.GetArray("userIds"),
		"dept_id")
}
func (c *AdminController) Person(r *ghttp.Request) *response.JsonResponse {
	c.Req.AdminId = token.GetLoginMemberId(r)
	return AdminService.Person(r.GetCtx(), c.Req)
}

func (c *AdminController) Permmenu(r *ghttp.Request) *response.JsonResponse {
	c.Req.AdminId = token.GetLoginMemberId(r)
	return AdminService.Permmenu(r.GetCtx(), c.Req)
}

func (c *AdminController) Logout(r *ghttp.Request) *response.JsonResponse {
	c.Req.AdminId = token.GetLoginMemberId(r)
	return AdminService.Logout(r, c.Req)
}

func (c *AdminController) PersonUpdate(r *ghttp.Request) *response.JsonResponse {
	c.Req.AdminId = token.GetLoginMemberId(r)
	return AdminService.PersonUpdate(r, c.Req)
}
